<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>出版社管理</title>
    <script id="header" type="text/javascript"
            src="../js/header.js?head=../"></script>
</head>
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>
    修改出版社 <a class="btn btn-success radius r mr-20"
            style="line-height: 1.6em; margin-top: 3px"
            href="javascript:location.replace(location.href);" title="刷新"><i
                class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="pd-20">
    <div style="width: 280px">
        <div class="text-c" >
            查询：<input type="text" id="searchDeptName" class="input-text radius size-S" placeholder="出版社名称" style="width: 150px;height: 32px">
            <button class="btn btn-primary radius" onclick="searchData()">查询</button>
        </div>

    </div>
    <div class="cl pd-5 bg-1 bk-gray">
			<span class="l"> <a href="javascript:;"
                                onclick="javascript:add();" id="saveData"
                                class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i>新增</a>
				<a href="javascript:;" onclick="bathDelete();" id="deleteData"
                   class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i>
					批量删除</a>
			</span>
    </div>
    <div class="mt-20">
        <table class="table table-border table-bordered table-hover table-bg table-sort" id="main">
            <thead>
            <tr class="text-c">
                <th width="25"><input type="checkbox" name="" value=""></th>
                <th width="50">id</th>
                <th width="100">出版社名称</th>
                <th width="100">市场占有率</th>
                <th width="100">畅销书占有率</th>
                <th width="100">新品占有率</th>
                <th width="100">新品贡献量</th>
                <th width="100">综合热度</th>
                <th width="100">总销售批次</th>
                <th width="100">创建时间</th>
                <th width="100">创建者</th>
                <th width="100">修改时间</th>
                <th width="100">修改者</th>
                <th width="100">操作</th>
            </tr>
            </thead>
        </table>
    </div>
</div>

<div id="formShow" class="pd-20" style="display: none;">
    <form action="" method="post" class="form form-horizontal" id="submitForm">
            <div class="row cl">
                <input id="id" name="id" style="display: none;" /> <input
                        id="dataType" name="dataType" style="display: none;" />
                <label class="form-label col-xs-2 col-sm-2 " for="name">
                    <span class="c-red">*</span>出版社名称：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="input-text" value="" placeholder=""
                           id="pbhouseName" name="pbhouseName" maxlength="1">
                </div>

                <label class="form-label col-xs-2 col-sm-2"><span
                            class="c-red">*</span>市场占有率：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="input-text" value="" placeholder=""
                           id="marketShare" name="marketShare" maxlength="1">
                </div>
            </div>


            <div class="row cl">
                <label class="form-label col-xs-2 col-sm-2"><span
                            class="c-red">*</span>畅销书占有率：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="input-text" value="" placeholder=""
                           id="bestSeller" name="bestSeller" maxlength="1">
                </div>

                <label class="form-label col-xs-2 col-sm-2"><span
                            class="c-red">*</span>新品占有率：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="input-text" value="" placeholder=""
                           id="newShare" name="newShare" maxlength="1">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-2 col-sm-2"><span
                            class="c-red">*</span>新品贡献量：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="input-text" value="" placeholder=""
                           id="newContribution" name="newContribution" maxlength="1">
                </div>

                <label class="form-label col-xs-2 col-sm-2"><span
                            class="c-red">*</span>综合热度：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="input-text" value="" placeholder=""
                           id="popular" name="popular" maxlength="1">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-2 col-sm-2"><span
                            class="c-red">*</span>总销售批次：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="input-text" value="" placeholder=""
                           id="totalBatch" name="totalBatch" maxlength="1">
                </div>
            </div>

        <div class="row cl">
            <div class="col-9 col-offset-3">
                <input class="btn btn-primary radius" id="submit" onclick="submitFrom()" value="提交">
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    var base = "../dataPbhouse/";
    var findPage = "findByPage";
    var findOne = "findDataPbhouseOne";
    var updateData = "updateDataPbhouse";
    var saveData = "saveDataPbhouse";
    var deleteData = "deleteDataPbhouse";
    var pageUrl = base + findPage;
    var editUrl = base + findOne;
    var updateUrl = base + updateData;
    var addUrl = base + saveData;
    var deleteUrl = base + deleteData;
    var pageSize = 7;
    var dataTable;
    $(function() {
        dataTable = MyDataTable({
            id : "main",
            pageUrl : pageUrl,
            param : function() {

                var p={"searchDeptName":$('#searchDeptName').val()};
                return p;

            },
            "columns" : [
                {
                    "orderable" : false,
                    "className" : 'text-c',
                    "render" : function(data, type, full) {
                        return '<td><input name="" type="checkbox" value="'+full.id+'"></td>';
                    }
                },{
                    "data" : "id",
                    "orderable" : false,
                    "className" : 'text-c',
                    "render" : function(data, type, full) {
                        if (data) {
                            return data;
                        }
                        return "";
                    }
                },

                {
                    "data" : "pbhouseName",
                    "orderable" : false,
                    "className" : 'text-c',
                    "render" : function(data, type, full) {
                        if (data) {
                            return data;
                        }
                        return "";
                    }
                },
                {
                    "data" : "marketShare",
                    "orderable" : false,
                    "className" : 'text-c',
                    "render" : function(data, type, full) {
                        if (data) {
                            return data;
                        }
                        return 0;
                    }
                },
                {
                    "data" : "bestSeller",
                    "orderable" : false,
                    "className" : 'text-c',
                    "render" : function(data, type, full) {
                        if (data) {
                            return data;
                        }
                        return "0";
                    }
                },
                {
                    "data" : "newShare",
                    "orderable" : false,
                    "className" : 'text-c',
                    "render" : function(data, type, full) {
                        if (data) {
                            return data;
                        }
                        return "0";
                    }
                },

                {
                    "data" : "newContribution",
                    "orderable" : false,
                    "className" : 'text-c',
                    "render" : function(data, type, full) {
                        if (data) {
                            return data;
                        }
                        return "0";
                    }
                },
                {
                    "data" : "popular",
                    "orderable" : false,
                    "className" : 'text-c',
                    "render" : function(data, type, full) {
                        if (data) {
                            return data;
                        }
                        return "0";
                    }
                },
                {
                    "data" : "totalBatch",
                    "orderable" : false,
                    "className" : 'text-c',
                    "render" : function(data, type, full) {
                        if (data) {
                            return data;
                        }
                        return "0";
                    }
                },
                {
                    "data" : "createTime",
                    "orderable" : false,
                    "className" : 'text-c',
                    "render" : function(data, type, full) {
                        if (data) {
                            return data;
                        }
                        return "无";
                    }
                },
                {
                    "data" : "createBy",
                    "orderable" : false,
                    "className" : 'text-c',
                    "render" : function(data, type, full) {
                        if (data) {
                            return data;
                        }
                        return "无";
                    }
                },
                {
                    "data" : "updateTime",
                    "orderable" : false,
                    "className" : 'text-c',
                    "render" : function(data, type, full) {
                        if (data) {
                            return data;
                        }
                        return "无";
                    }
                },
                {
                    "data" : "updateBy",
                    "orderable" : false,
                    "className" : 'text-c',
                    "render" : function(data, type, full) {
                        if (data) {
                            return data;
                        }
                        return "无";
                    }
                },
                {
                    "orderable" : false,
                    "className" : 'text-c',
                    "render" : function(data, type, full) {
                        return "<a class="
                            + updateData
                            + "  title = '修改' onclick='edit(\""
                            + full.id
                            + "\");'><i class='Hui-iconfont'>&#xe6df;</i></a>"
                            + "&#12288;<a  class="
                            + deleteData
                            + "  title = '删除' onclick='deletePlat(\""
                            + full.id
                            + "\");'><i class='Hui-iconfont'>&#xe6e2;</i></a>";
                    }
                } ]
        });

    });

    function bathDelete() {
        var ids = [];
        $("#main input:checked").each(function(i) {
            if ($(this).val() != '') {
                ids.push($(this).val());
            }
        });
        if (ids.length == 0) {
            layer.msg("至少选择一行进行操作!");
            return;
        }
        deletePlat(ids.join(","));

    };

    function deletePlat(ids) {
        layer.confirm('你真的要删除勾选的行?', function(index) {
            layer.load();
            layer.close(index);
            $.ajax({
                url : deleteUrl,
                type : 'get',
                datatype : 'json',
                data : {
                    "ids" : ids
                },
                success : function(result) {
                    if (result.code==200) {
                        layer.msg(result.msg);
                        searchData();
                    } else {
                        layer.msg(result.msg);
                    }
                }
            });
        });
    }
    function searchData() {
        dataTable.ajax.reload(null, false);
    };

    /**
     * 清空表单信息
     */
    function clearFrom() {
        $('#submitForm')[0].reset();
    };

    /**
     * 编辑用户
     * @param id
     */
    function edit(id) {
        clearFrom();
        var form = $("#submitForm");
        //设置表单提交 地址
        form.attr("action", updateUrl);
        $.ajax({
            url : editUrl,
            type : 'get',
            datatype : 'json',
            data : {
                "id" : id
            },
            success : function(result) {
                layer.closeAll();
                $('#formShow').show();
                layer.open({
                    title : '修改',
                    type : 1,
                    area : [ '80%', '60%' ], //宽高s
                    content : $('#formShow')
                });
                //填充表单信息
                for ( var d in result) {
                    var $obj = $("#" + d);
                    if ($obj.length > 0) {
                        var tagName = $obj[0].tagName;
                        if (tagName == "IMG") {
                            $obj.attr("src", "" + result[d] + "");
                        } else {
                            $obj.val(result[d] + "");
                        }
                    }
                }
            }
        });
    };

    /**
     * 提交表单
     */
    function submitFrom() {
        var form = $("#submitForm");
        layer.load();
        var options = {
            type : 'post',
            success : function(data) {
                layer.closeAll();
                if (data.code==200) {
                    searchData();
                } else {
                    layer.msg(data.msg);
                }
            }
        };
        form.ajaxSubmit(options);
    };

    $("#submitForm").validate({
        rules : {
            nickname : {
                required : true
            },
        },
        onkeyup : false,
        focusCleanup : true,
        success : "valid",
        submitHandler : function(form) {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
            submitFrom();
        }
    });


    function add() {
        clearFrom();
        var form = $("#submitForm");
        form.attr("action", addUrl);
        $('#formShow').show();
        layer.open({
            title : '添加',
            type : 1,
            area : [ '80%', '60%' ], //宽高s
            content : $('#formShow')
        });

    };
</script>
</body>
</html>